package com.loop.practice;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Random;

public class PracticeDemo1 {
    public static void main(String[] args) {
        HashSet<Integer> set = storeDifferNum();
        Iterator<Integer> iterator = set.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }
    /**
     * 使用合适的容器存储5个不重复的1-99之间的任意随机整数
     */
    public static HashSet<Integer> storeDifferNum(){
        Random random = new Random();
        HashSet<Integer> set = new HashSet<>();
        for (int i = 0; i < 5; i++) {
            boolean flag = set.add(random.nextInt(5)+1);
            if (!flag){
                i--;
            }
        }
        return set;
    }
}
